package com.xcc.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @author frosty
 * @description 跨域设置
 * @date 2019-11-29 29:13:59
 */

@Configuration
public class CorsConfig {

    private CorsConfiguration buildConfig(){

        CorsConfiguration corsConfiguration=new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");  //允许任何域名使用
        corsConfiguration.addAllowedMethod("*");  //允许任何方式的请求  get  post
         corsConfiguration.addAllowedHeader("*"); //允许的请求头
         return  corsConfiguration;
    }

@Bean
public CorsFilter corsFilter(){
    UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**",buildConfig());  //对接口设置跨域请求
    return  new CorsFilter(source);


}

}
